package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Reference
    MenuService menuService;
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
            PageResult pageResult = menuService.findPage(queryPageBean);
        return pageResult;
    }
    @RequestMapping("/findAll")
    public Result findAll(){

      List<Menu> menuList= menuService.findAll();
      return new Result(true, MessageConstant.GET_MENU_SUCCESS,menuList);
    }
    @RequestMapping("/findByUserId")
    public Result findByUserId(int id){

        List<Menu> menuList= menuService.findByUserId(id);
        return new Result(true, MessageConstant.GET_MENU_SUCCESS,menuList);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Menu menu){

        menuService.update(menu);
        return new Result(true, MessageConstant.GET_MENU_SUCCESS);
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Menu menu){

        menuService.add(menu);
        return new Result(true, MessageConstant.GET_MENU_SUCCESS);
    }
    @RequestMapping("/delete")
    public Result delete(int id){

        menuService.delete(id);
        return new Result(true, MessageConstant.GET_MENU_SUCCESS);
    }




}
